using System;
using System.Collections.Generic;

namespace AutoChess
{ 
    class ActorAttrData
    {
        public Dictionary<int,double> m_actorAttrMap = new Dictionary<int, double>();

        private GameActor m_owner;
        private bool m_init = false;

        public void SetOwner(GameActor owner)
        {
            m_owner = owner;
        }

        public GameActor GetOwner()
        {
            return m_owner;
        }

        public bool SetAttr(ActorAttrDataType actorAttrDataType, double value)
        {
            double existVal;
            if (m_actorAttrMap.TryGetValue((int) actorAttrDataType, out existVal) && existVal.Equals(value))
            {
                return false;
            }

            m_actorAttrMap[(int) actorAttrDataType] = value;
            if (m_init)
            {
                return true;
            }

            m_init = true;
            return false;
        }

        public double GetAttr(ActorAttrDataType actorAttrDataType)
        {
            double existVal = 0;
            m_actorAttrMap.TryGetValue((int) actorAttrDataType, out existVal);
            return existVal;
        }

        public Int64 HP
        {
            get { return (Int64) GetAttr(ActorAttrDataType.HP); }
            set
            {
                if (value == 0)
                {
                    ActorHelper.SetDie(m_owner);
                }

                bool ret = SetAttr(ActorAttrDataType.HP, Math.Min(value, GetAttr(ActorAttrDataType.MAXHP)));
                if (ret)
                {
                    GameEvent.Get<IActorLogic>().OnActorHpChange(m_owner.SvrActorId);
                }
            }
        }

        public float HPPercent
        {
            get
            {
                var maxHp = GetAttr(ActorAttrDataType.MAXHP);
                if (maxHp < 0.01f)
                {
                    return 0f;
                }

                return (float) (GetAttr(ActorAttrDataType.HP) / maxHp);
            }
        }

        public static void UpdateActorData(ActorAttrData mAttrData, Dictionary<int, double> runAttrData)
        {
            throw new NotImplementedException();
        }
    }

    static class ActorDataUtil
    {
    }
}